package com.top.ruizhong.main.host

import android.app.Activity
import android.content.Intent
import android.view.MotionEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.blankj.utilcode.util.FragmentUtils
import com.module.lemlin.base.BaseAbstractActivity
import com.top.ruizhong.R
import kotlinx.android.synthetic.main.activity_search.*

class SearchActivity : BaseAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, SearchActivity::class.java)
            activity.startActivity(intent)
        }
    }

    override val layoutResId: Int
        get() = R.layout.activity_search

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, view = flSearchBar)
    }

    override fun initView() {
        tvSearchClose.setOnClickListener { this.finish() }

        etSearchContent.setOnEditorActionListener { v, actionId, event ->
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                FragmentUtils.replace(
                    supportFragmentManager,
                    SearchGoodsFragment.newInstance(),
                    R.id.frameSearch, (true),
                    R.animator.slide_right_in,
                    R.animator.slide_left_out,
                    R.animator.slide_left_in,
                    R.animator.slide_right_out
                )
                return@setOnEditorActionListener true
            }
            return@setOnEditorActionListener false
        }

        FragmentUtils.add(
            supportFragmentManager,
            SearchRecordFragment.newInstance(),
            R.id.frameSearch
        )
    }

    fun onClick(view: View) {
        FragmentUtils.replace(
            supportFragmentManager,
            SearchGoodsFragment.newInstance(),
            R.id.frameSearch, (true),
            R.animator.slide_right_in,
            R.animator.slide_left_out,
            R.animator.slide_left_in,
            R.animator.slide_right_out
        )
    }
}